package hkr.se1.budgetapp;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.content.pm.ActivityInfo;

public class MainActivity extends Activity {
	public EntriesDataSource EDS;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		
		EDS = new EntriesDataSource(this);
		EDS.open();
		
		ActionBar actionBar = setupActionBar();
		createTabs(actionBar);
		
	}
	public EntriesDataSource getEntriesDataSource(){
		return EDS;
	}
	private ActionBar setupActionBar() {
		// setup action bar for tabs
		ActionBar actionBar = getActionBar();
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		return actionBar;
	}

	private void createTabs(ActionBar actionBar) {
		Tab tab = actionBar
				.newTab()
				.setText(R.string.register_tab)
				.setTabListener(
						new TabListener<RegisterFragment>(this, "register",
								RegisterFragment.class));
		actionBar.addTab(tab);

		tab = actionBar
				.newTab()
				.setText(R.string.graph_tab)
				.setTabListener(
						new TabListener<GraphFragment>(this, "graph",
								GraphFragment.class));
		actionBar.addTab(tab);

		tab = actionBar
				.newTab()
				.setText(R.string.budget_tab)
				.setTabListener(
						new TabListener<BudgetFragment>(this, "budget",
								BudgetFragment.class));
		actionBar.addTab(tab);
		
		tab = actionBar
				.newTab()
				.setText(R.string.list_tab)
				.setTabListener(
						new TabListener<ListFragment>(this, "list",
								ListFragment.class));
	
		actionBar.addTab(tab);
	}
}
